Skip to content

[Vertex AI] Add countTokens support for Developer API via VinF #14644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2025

Conversation

andrewheard
Copy link
Contributor

Added support for countTokens using the Developer API through the Vertex AI in Firebase (firebasevertexai.googleapis.com) backend. This combination is an edge case where the model resource name (e.g., projects/my-project/models/gemini-2.0-flash) in the countTokens request URL differs from the resource name in the request field CountTokensRequest.generateContentRequest.name. The integration tests have been updated to perform a countTokens request using both firebasevertexai.googleapis.com (Vertex AI and Developer API) and generativelanguage.googleapis.com (Developer API only) to ensure no regressions.

#no-changelog

Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

@andrewheard
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for countTokens using the Developer API through the Vertex AI in Firebase backend. The changes include modifications to the GenerativeModel, VertexAI, and CountTokensRequest classes to handle the different model resource name formats required by the various backends. Integration tests have also been updated to ensure no regressions. Overall, the changes seem well-structured and address the specific edge case described in the pull request description.

Summary of Findings

  • Model Name Handling: The introduction of the modelName property in GenerativeModel and its usage in constructing the generateContentRequestModelResourceName seems like a good approach to handle the different model name formats. However, it's crucial to ensure that this new property is always correctly initialized and used consistently throughout the codebase.
  • Code Duplication: The developerModelResourceName function in VertexAI.swift has similar logic for .firebaseVertexAIStaging and .firebaseVertexAIProd. Consider refactoring to reduce code duplication.
  • Test Coverage: The integration tests have been updated, but it's important to ensure that all edge cases and different configurations are thoroughly tested to prevent regressions.
  • Documentation: The documentation for the modelResourceName parameter in the GenerativeModel initializer is comprehensive and helpful. Ensure that all public APIs are well-documented.

Merge Readiness

The pull request introduces important functionality for handling a specific edge case with the countTokens API. The code appears to be well-structured and addresses the issue effectively. However, before merging, it's recommended to address the potential code duplication in developerModelResourceName and ensure comprehensive test coverage for all configurations. I am unable to directly approve this pull request, and other reviewers should review and approve this code before merging.

@andrewheard andrewheard marked this pull request as ready for review April 9, 2025 22:39
@andrewheard andrewheard requested a review from paulb777 April 9, 2025 22:39
@andrewheard andrewheard merged commit 11fe4a0 into main Apr 9, 2025
37 checks passed
@andrewheard andrewheard deleted the ah/vertex-dev-count-tokens branch April 9, 2025 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants